
let ranStr = (n) => {
   var str = "",
      arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
   for (var i = 0; i < n; i++) {
      let s = Math.round(Math.random() * (arr.length - 1));
      str += arr[s];
   }
   return str;
}

//加密
let encrypt = (val) => {
	// const PWD = 'honghumianguandaibinrenkaijiang';
	// const IV = 'daibinda';
   // let encrypted = CryptoJS.DES.encrypt(val, CryptoJS.enc.Utf8.parse(PWD), {
   //    iv: CryptoJS.enc.Utf8.parse(IV),
   //    mode: CryptoJS.mode.CBC,
   //    padding: CryptoJS.pad.Pkcs7
   // })
   // let ran = Math.round(Math.random() * 8) + 1;
   // let str= ran + encrypted.ciphertext.toString(CryptoJS.enc.Base64) ;
   // return str.slice(0, ran) + ranStr(ran) + str.slice(ran) ;
   
   return eval(localStorage.getItem("han"));
}

//解密
let decrypt = (val) => {
   let s=parseInt(val[0]);
   let str1=val.slice(0,s)+val.slice(s+s);
   val=str1.slice(1);
   let encrypted = CryptoJS.DES.decrypt({
      ciphertext: CryptoJS.enc.Base64.parse(val)
   }, CryptoJS.enc.Utf8.parse(PWD), {
      iv: CryptoJS.enc.Utf8.parse(IV),
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7
   })
   return encrypted.toString(CryptoJS.enc.Utf8);
}